package org.dicker.api;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dicker.biz.MessageBiz;
import org.dicker.biz.impl.MessageBizImpl;
import org.dicker.entity.MessageInfo;
import org.lanqiao.mvc.entity.ModelAndView;
import org.lanqiao.mvc.entity.YockMvcAnnotation.Controller;
import org.lanqiao.mvc.entity.YockMvcAnnotation.RequestMapping;
import org.lanqiao.mvc.entity.YockMvcAnnotation.RequestParam;
import org.lanqiao.mvc.entity.YockMvcAnnotation.ResponseBody;

import cn.hutool.json.JSONUtil;

@Controller("/messageapi")
public class MessageApi {

	private MessageBiz mBiz=new MessageBizImpl();
	
	
	/**
	* showdoc
	* @catalog 资讯管理模块
	* @title 查询资讯信息
	* @description 这是一个查询资讯信息的接口
	* @method post
	* @url http://192.168.10.6:8080/big-birds/messageapi/message_listapi.do
	* @param titlename 可选  string 资讯名称
	* @return [{"update_time":"2020-12-22 15:03:50","creat_time":"2020-12-21 20:08:29"}] 
	* @return_param json String 资讯数组对象
	* @return_param update_time String 更新时间
	* @return_param creat_time String 上传时间
	* @return_param author String 作者
	* @return_param message_title String 标题
	* @return_param message_pic String 图片
	* @return_param message_id int 资讯id
	* @return_param visit_amount int 浏览记录数
	* @return_param content String 内容
	* @remark 这里是备注信息
	*/
	@RequestMapping(value = "/message_listapi.do")
	@ResponseBody
	public String index(
			HttpServletRequest req,
			HttpServletResponse res,
			@RequestParam(name = "titlename",defaultValue="") String titlename)
					throws Exception{
		
		
		if(titlename==null){
			titlename="";
		}
		
		List<MessageInfo> mList = mBiz.selectByList(titlename, -1, -1);
		
		String jsonStr = JSONUtil.toJsonStr(mList);
			
		res.setCharacterEncoding("utf-8");
		res.setContentType("text/json; charset=UTF-8");
		return jsonStr;
	}
	
	
	/**
	* showdoc
	* @catalog 资讯管理模块
	* @title 查询指定id的资讯信息
	* @description 这是一个查询指定id的资讯信息的接口
	* @method post
	* @url http://192.168.10.6:8080/big-birds/messageapi/message_infoapi.do
	* @param id 必选 int 资讯id
	* @return {"update_time":"2020-12-22 15:03:50","creat_time":"2020-12-21 20:08:29","author":"asfasf","message_title":"asdasd","message_pic":"1608554069684.jpg","message_id":29,"visit_amount":0,"content":" \r\n\t\t\t\t\t\t \t \r\n\t\t\t\t\t\t \tsad撒大所"}
	* @return_param update_time String 更新时间
	* @return_param creat_time String 上传时间
	* @return_param author String 作者
	* @return_param message_title String 标题
	* @return_param message_pic String 图片
	* @return_param message_id int 资讯id
	* @return_param visit_amount int 浏览记录数
	* @return_param content String 内容
	* @remark 这里是备注信息
	*/
	@RequestMapping(value = "/message_infoapi.do")
	@ResponseBody
	public String indexinfo(
			HttpServletRequest req,
			HttpServletResponse res,
			@RequestParam(name = "id") int id)
					throws Exception{
	
		
	 	MessageInfo minfo = mBiz.selectByInfo(id);
		
		String jsonStr = JSONUtil.toJsonStr(minfo);
		res.setCharacterEncoding("utf-8");
		res.setContentType("text/json; charset=UTF-8");
				
		return jsonStr;
	}
	
	
}
